package org.example.practicaltraining.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.example.practicaltraining.commom.Result;
import org.example.practicaltraining.entity.message;
import org.example.practicaltraining.mapper.messageMapper;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/message")
@ResponseBody
public class messageController {
    @Resource
    messageMapper messageMapper;
    //获取留言
    @GetMapping("/getMessage/{id}")
    public Result<?> getMessage(@PathVariable("id") Integer id) {
        return Result.success(messageMapper.selectById(id));
    }

    @GetMapping
    public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "8") Integer pageSize){
        LambdaQueryWrapper<message> wrappers = Wrappers.<message>lambdaQuery();
        Page<message> userPage =messageMapper.selectPage(new Page<>(pageNum,pageSize), wrappers);
        return Result.success(userPage);
    }

    //获取所有好评的留言
    @GetMapping("/getGoodMessage")
    public Result<?> getGoodMessage() {
        LambdaQueryWrapper<message> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.gt(message::getGood, 0); // gt表示大于，这里设置好评数量大于0为查询条件
        return Result.success(messageMapper.selectList(queryWrapper));
    }
    @GetMapping("/getMiddleMessage")
    public Result<?> getMiddleMessage() {
        LambdaQueryWrapper<message> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.gt(message::getMiddle, 0); // gt表示大于，这里设置好评数量大于0为查询条件
        return Result.success(messageMapper.selectList(queryWrapper));
    }
    @GetMapping("/getBadMessage")
    public Result<?> getBadMessage() {
        LambdaQueryWrapper<message> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.gt(message::getBad, 0); // gt表示大于，这里设置好评数量大于0为查询条件
        return Result.success(messageMapper.selectList(queryWrapper));
    }

}
